package kin.test;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.metamodel.EntityType;

import kin.converter.ARPBeanUtils;
import kin.converter.ARPBeanUtilsBean;
import kin.converter.ARPConvertUtilsBean;
import kin.converter.BeanTypeConverter;


import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.beanutils.BeanUtils;






public class t1 {
	
	
public static void main(String[] args) {

	
	Class cls=Us.class;
	Us u=new Us();
	List<String> l=new ArrayList<String>();
	l.add("a");
	l.add("b");
	
	List<Us> uss=new ArrayList<Us>();
	Us u1=new Us();
	u1.setUs_id(1);
	Us u2=new Us();
	u2.setUs_id(2);
	uss.add(u1);
	uss.add(u2);
	String[] aa={"1","2"};
	String pp="3";
	//System.out.println(aa);
	try {
		//ConvertUtils.deregister();
		//ARPConvertUtilsBean aaa=new ARPConvertUtilsBean();
		//aaa.deregister();
		System.out.println(Us.class.getSuperclass().getSimpleName());
		//ConvertUtils.register(new BeanTypeConverter(),Us.class);
		//ARPBeanUtilsBean p=new ARPBeanUtilsBean();
		ARPBeanUtils.copyProperty(u, "parent",pp);
		ARPBeanUtils.copyProperty(u, "uss",aa);
		//BeanUtils.copyProperty(u, "parent",pp);
		//BeanUtils.copyProperty(u, "uss",aa);
		System.out.println("id:"+u.getParent().getUs_id());
		if(u.getChildren()!=null)
		for(Us s:u.getChildren()){
			System.out.println(s.getUs_id());
		}
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	//ConvertUtils.deregister( List.class);
	
	/*Object o = null;
	try {
		int index=0;
		Field f=cls.getDeclaredField("m");
		Class c=f.getType();
		System.out.println(c.isPrimitive());
		
		if(c==List.class){
			System.out.println(c.getSimpleName());
		}
		Type genericFieldType=f.getGenericType();
		//System.out.println(f.getGenericType());
		if (genericFieldType instanceof ParameterizedType) {
			ParameterizedType aType = (ParameterizedType) genericFieldType;
			Type[] fieldArgTypes = aType.getActualTypeArguments();
			if (index >= fieldArgTypes.length || index < 0) {
			throw new RuntimeException("你输入的索引"+ (index < 0 ? "不能小于0" : "超出了参数的总数"));
			}
			for(int i=0;i<fieldArgTypes.length;i++){
			o= (Class) fieldArgTypes[i];
			System.out.println(((Class) o).getSimpleName());
			}
			}
			//o= Object.class;
			

	} catch (SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (NoSuchFieldException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}*/
	
		
			
		
		
	
	
	/*for (int i = 0; i < descriptors.length; i++) {
		PropertyDescriptor descriptor = descriptors[i];
		if ("containedBeans".equals(descriptor.getName())) {
			assertTrue("Property should be an array", descriptor.getPropertyType().isArray());
			assertEquals(descriptor.getPropertyType().getComponentType(), ContainedBean.class);
		}
	}*/
	
}
	/*ConvertUtils.register(new ListTypeConverter(), List.class);
	
	List<String> l=new ArrayList<String>();
	l.add("a");
	l.add("b");
	Us u=new Us();
	try {
		BeanUtils.copyProperty(u, "list",l);
		
	} catch (IllegalAccessException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (InvocationTargetException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}*/
}
